package com.huak.boot.listener;

import org.springframework.boot.context.config.ConfigFileApplicationListener;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.core.Ordered;

/**
 * {@link ConfigFileApplicationListener }
 * @author LR2SD
 * @description
 * @date 2019-03-30 10:54
 */
public class BeforeConfigFileApplicationListener implements Ordered ,SmartApplicationListener {

    @Override
    public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
        return ApplicationEnvironmentPreparedEvent.class.isAssignableFrom(eventType)
                || ApplicationPreparedEvent.class.isAssignableFrom(eventType);
    }

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        if (event instanceof ApplicationEnvironmentPreparedEvent) {
            ApplicationEnvironmentPreparedEvent environmentPreparedEvent=(ApplicationEnvironmentPreparedEvent)event;
            String name=environmentPreparedEvent.getEnvironment().getProperty("name");
            System.out.println("environmentPreparedEvent.getEnvironment().getProperty(\"name\")=="+name);
        }
        if (event instanceof ApplicationPreparedEvent) {

        }
    }

    @Override
    public int getOrder(){
        return ConfigFileApplicationListener.DEFAULT_ORDER+1;
    }


}
